package com.gzhryc.shared_device.oem.code.place.dao;

import com.gzhryc.jdbc.BaseDao;
import com.gzhryc.jdbc.Conditions;
import com.gzhryc.jdbc.Query;
import com.gzhryc.shared_device.oem.code.place.dao.db.PlaceProfitUser;
import com.gzhryc.shared_device.oem.code.place.dao.models.PlaceUserCount;
import com.gzhryc.shared_device.oem.code.place.dao.models.RoleTypePlaceCount;
import com.gzhryc.shared_device.oem.code.place.dao.models.UserProfitPlaceCount;

import java.sql.SQLException;
import java.util.List;

public class PlaceProfitUserDao extends BaseDao<PlaceProfitUser> {

    public PlaceProfitUserDao(String jdbcKey) {
        super(jdbcKey);
    }

    public List<UserProfitPlaceCount> countGroupUserId(Conditions conditions) throws SQLException {
        String sql = "SELECT user_id AS userId,COUNT(1) AS placeCount FROM " + this.tableName;
        Query query = new Query(sql);
        query.appendSql(conditions.toSql(query.getParams(),true));
        query.appendSql(" GROUP BY user_id");
        return this.jdbcHelper.find(query,UserProfitPlaceCount.class);
    }
    
    public List<RoleTypePlaceCount> countGroupRoleType(Conditions conditions) throws SQLException {
        String sql = "SELECT role_type as roleType,COUNT(1) AS placeCount FROM " + this.tableName;
        Query query = new Query(sql);
        query.appendSql(conditions.toSql(query.getParams(),true));
        query.appendSql(" GROUP BY role_type");
        return this.jdbcHelper.find(query,RoleTypePlaceCount.class);
    }

    public List<PlaceUserCount> countGroupPlaceId(Conditions conditions) throws SQLException {
        String sql = "SELECT place_id AS placeId,COUNT(1) AS userCount FROM " + this.tableName;
        Query query = new Query(sql);
        query.appendSql(conditions.toSql(query.getParams(),true));
        query.appendSql(" GROUP BY place_id");
        return this.jdbcHelper.find(query,PlaceUserCount.class);
    }
}
